/**
 * Copyright (c) 2009 Jim Hurne
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package org.tzconverter.gui;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;

/**
 * 
 * @author Jim Hurne
 * @since Jul 27, 2009
 */
public class GradientButton extends JButton
{
  private static final long serialVersionUID = -5261651615876020355L;

  /**
   * 
   */
  public GradientButton()
  {
    super();
    init();
  }

  /**
   * @param arg0
   */
  public GradientButton(Action arg0)
  {
    super(arg0);
    init();
  }

  /**
   * @param arg0
   */
  public GradientButton(Icon arg0)
  {
    super(arg0);
    init();
  }

  /**
   * @param arg0
   * @param arg1
   */
  public GradientButton(String arg0, Icon arg1)
  {
    super(arg0, arg1);
    init();
  }

  /**
   * @param arg0
   */
  public GradientButton(String arg0)
  {
    super(arg0);
    init();
  }

  /**
   * 
   */
  private void init()
  {
    setContentAreaFilled(false);
    setForeground(Color.WHITE);
  }

  @Override
  protected void paintComponent(Graphics g)
  {
    Graphics2D g2 = (Graphics2D) g;
    Paint oldPaint = g2.getPaint();

    GradientPaint paint = new GradientPaint(0, 0, Color.LIGHT_GRAY, 0, this.getHeight(), Color.DARK_GRAY);
    
    g2.setPaint(paint);
    g2.fillRect(0, 0, this.getWidth(), this.getHeight());
    
    g2.setPaint(oldPaint);
    super.paintComponent(g);
  }
  
}
